package action;

import biz.UserBiz;
import biz.impl.UserBizImpl;
import entity.Users;
import entity.return_type.BooleanMsg;
import entity.return_type.DataNoPaging;
import util.HttpIOUtil;

public class UserAction extends SuperAction {

	/**
	 * 用户Action
	 * 
	 * @anthor billdonwey
	 */
	private static final long serialVersionUID = 1L;
	private static final UserBiz USER_BIZ = new UserBizImpl();

	// 用户注册
	public void userRegister() {
		Users users = new Users();
		users.setUsername(params.getString("username"));
		users.setPassword(params.getString("password"));
		users.setNickname(params.getString("nickname"));
		users.setHeadImg("images/head_image.jpg");
		HttpIOUtil.ObjectToWeb(response, USER_BIZ.userRegister(users));
	}

	// 用户登录
	public void userLogin() {
		String username = params.getString("username");
		String password = params.getString("password");
		Users users = USER_BIZ.userLogin(username, password);
		if (users == null) {
			BooleanMsg out = new BooleanMsg();
			out.setMsg("登陆失败，请检查用户名和密码是否正确！");
			out.setSuccess(false);
			HttpIOUtil.ObjectToWeb(response, out);
		} else {
			DataNoPaging out = new DataNoPaging();
			out.setData(users);
			out.setMsg("登陆成功");
			HttpIOUtil.ObjectToWeb(response, out);
		}
	}

}
